# -*- coding: utf-8 -*-
"""
 Created by wq.wang on 2017/12/20
"""
import logging

from wserver.django import DjangoWApi, DjangoService

_logger = logging.getLogger(__name__)
from wserver.base.field import Object, Integer, Float, String, Boolean, Dictionary


class CeModel(Object):
    username = String('用户名', True)
    money = Float('资产')
    age = Integer('年纪')
    acitve = Boolean('是否激活')


car_info = {
    "username": String('用户名', True),
    "money": Float('资产'),
    "age": Integer('年纪')
}


class UserSerive(DjangoService):
    """
        一个服务实例说明
    """
    pre_url = "demo"

    @DjangoWApi.api()
    def get(self, username):
        return "json"

    @DjangoWApi.api()
    def post(self, username, password, age: int):
        """
        创建用户
        :param username: 用户名
        :param password:  密码
        :param age:  年龄
        :return:
        """
        return {"userid": 12}

    @DjangoWApi.api()
    def put(self, userid: int, username, pwd, age: int):
        """
        修改用户消息接口
        :param userid:
        :param username:
        :param pwd:
        :param age:
        :return:
        """
        return {"status": "修改成功"}

    @DjangoWApi.api()
    def delete(self, userid: int):
        """
        删除员工
        :param userid:
        :return:
        """
        return "删除用户%s成功" % userid

    @DjangoWApi.api()
    def demo(self, user1: CeModel, user2: Dictionary(car_info), users1: [CeModel], users2: [car_info]):
        """

        :param user1:
        :param user2:
        :param users1:
        :param users2:
        :return: {
                "userid":122 // 这个是用户id
                            }
        """
        return "ok"

    @DjangoWApi.api()
    def demo1(self, username):
        """
        普通函数，无注释参数类型，默认为str
        :param username: 用户名称
        :return:
        {
            "id":12 // 用户id
        }
        """
        return "ok"

    @DjangoWApi.api()
    def demo2(self, userid: int, age: int, username: str, active: bool):
        """
        普通函数，注释参数
        :param userid: 用户id
        :param age: 年龄
        :param username: 用户名称
        :param active: 是否激活
        :return:
        """
        return "ok"

    @DjangoWApi.api()
    def demo3(self, username, userid: int):
        """
        位置可变参数
        :param userid: 用户id
        :param username: 用户名称
        :return:
        """
        return "ok"

    @DjangoWApi.api()
    def demo4(self, username, userid: int, **kwargs):
        """
        关键字可变参数
        :param userid: 用户id
        :param username: 用户名称
        :param kwargs: 用户其余属性
        :return:
        """
        return "ok"
